#!/bin/bash

echo "=========================================="
echo "  Starting SimpleOS in QEMU"
echo "=========================================="

# 检查操作系统镜像是否存在
if [ ! -f os-image.bin ]; then
    echo "[ERROR] OS image not found!"
    echo "Please run ./build.sh first"
    exit 1
fi

# 检查 QEMU 是否安装
if ! command -v qemu-system-i386 &> /dev/null && ! command -v qemu-system-x86_64 &> /dev/null; then
    echo "[ERROR] QEMU not found!"
    echo "Please install QEMU:"
    echo "  Ubuntu/Debian: sudo apt-get install qemu-system-x86"
    echo "  Fedora: sudo dnf install qemu-system-x86"
    echo "  Arch: sudo pacman -S qemu"
    exit 1
fi

echo "[INFO] Launching QEMU with 128MB RAM..."
echo "[INFO] Press Ctrl+C or close window to exit"
echo ""

# 使用 QEMU 运行操作系统（软盘模式，BIOS兼容性最好）
# -fda: 作为软盘A加载
# -boot a: 从软盘启动
if command -v qemu-system-i386 &> /dev/null; then
    qemu-system-i386 -fda os-image.bin -boot a
else
    qemu-system-x86_64 -fda os-image.bin -boot a
fi

